package com.htl.集合;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayList__test {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add("Hello");
        arrayList.add("World");
        arrayList.add("JavaSE");
        arrayList.add("JavaME");
        arrayList.add("JavaEE");
        System.out.println(arrayList.toString());
        System.out.println("集合长度："+arrayList.size());
        System.out.println("集合是否包含Hello：" + arrayList.contains("Hello"));
        System.out.println("-----------------------------------------------");

        //迭代器
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("===============================================");

        //for循环
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(arrayList.get(i));
        }
        System.out.println("-----------------------------------------------");

        System.out.println("删除之前的集合是：" + arrayList);
        arrayList.remove(2);
        System.out.println("------------------------------------------------------");
        System.out.println("删除之后的集合是：" + arrayList);
        System.out.println("======================================================");
        arrayList.remove("World");
        System.out.println("删除之后的集合是：" + arrayList);
        System.out.println("------------------------------------------------------");
        arrayList.add(2, "OK");
        System.out.println("添加之后的集合是：" + arrayList);
        System.out.println("======================================================");
        arrayList.set(2, "TEST");
        System.out.println(arrayList);
        System.out.println(arrayList.indexOf("TEST2"));
    }
}
